<?php
// 处理模块分区的文件
include '../init.php';

// 修改模块的状态
$zid = $_GET['zid'];
$action = $_GET['action'];
if ($action=="enabled") {
	$data = array();
	$sql  = "UPDATE `zone_modul_tb` SET status=1 WHERE zid={$zid}";
	if(!my_mysql_query($sql, $data)){
		show_msg(1,'激活模块失败', 3, 'index.php?action=4');
		exit();
	}
	show_msg(0,'激活模块成功', 2, 'index.php?action=4');
	exit();
}

if ($action=="disable") {
	$data = array();
	$sql  = "UPDATE `zone_modul_tb` SET status=0 WHERE zid={$zid}";
	if(!my_mysql_query($sql, $data)){
		show_msg(1,'停用模块失败', 3, 'index.php?action=4');
		exit();
	}
	show_msg(0,'停用模块成功', 2, 'index.php?action=4');
	exit();
}

$uid    = $_SESSION['uid'];
$action = $_POST['action'];
$title  = $_POST['title'];
$intro  = $_POST['intro'];
$time = time();

// 处理分区
if ($action == 2) {
	$data = array();
	$sql  = "INSERT INTO `zone_modul_tb`(zid,title,intro,create_time,create_uid) ";
	$sql .= "VALUES (null, '{$title}', '{$intro}', {$time}, {$uid});";
	if(!my_mysql_query($sql, $data)){
		show_msg(1,'添加分区错误', 3, 'index.php?action='.$action);
		exit();
	}

	show_msg(0,'添加分区成功', 2, 'index.php?action='.$action);
	exit();
}


// 处理模块
if ($action == 3) {
	$info = execute_file($_FILES['image']);
	if ($info === false) {
        var_dump('11111111111111111');
		show_msg(1,'添加模块错误', 3, 'index.php?action='.$action);
		exit();
	}

	$data = array();
	$imageid = $info['insertid'];
	$parentid = $_POST['parentid'];
	$sql  = "INSERT INTO `zone_modul_tb`(zid,parentid,imageid,title,intro,create_time,create_uid) ";
	$sql .= "VALUES (null, {$parentid}, {$imageid}, '{$title}', '{$intro}', {$time}, {$uid});";
	if(!my_mysql_query($sql, $data)){
        var_dump('11111111111111111');
		show_msg(1,'添加模块错误', 3, 'index.php?action='.$action);
		exit();
	}

	show_msg(0,'添加模块成功', 2, 'index.php?action='.$action);
	exit();
}

?>